<?php

/**
 * @Description    后台登陆控制器
 * @Author         zhaojiping
 * @Copyright      山东艾思软件科技有限公司(https://www.aisisofit.cn)
 * @Date           2022/1/20
 * @CreateBy       VS
 */

namespace app\core\controller;

use app\BaseController;
use app\core\model\CoreUser;
use ric\captcha\facade\CaptchaApi;

class LoginController extends BaseController {

    public function login() {
        $code = input('code', '');
        $key = input('key', '');
        /* 检测验证码 */
        //if (!CaptchaApi::check($code, $key)) json_return(0, '验证码输入错误');

        $username = trim(input('username', ''));
        $password = trim(input('password', ''));

        if (strlen($username) < 4 || strlen($password) < 6) json_return(0, '您输入的用户或密码格式有错误');

        CoreUser::login($username, $password);
    }

    //生成验证码
    public function verify() {
        $captch = CaptchaApi::create();
        $data['base64'] = $captch['base64'];
        $data['key'] = $captch['key'];
        $data['md5'] = $captch['md5'];
        json_return(1, '验证码信息', $data);
    }
}
